import { _decorator, Vec2 } from 'cc';
import { SandBlast_GameStorage } from './SandBlast_GameStorage';

export class SandBlast_GameData {
    static item_score: number = 10;

    static arrGrids: any[][] = [];
    static arrCardGroups: any[] = [];
    //    /** StartPos */
    static StartPos: Vec2;
    //    /** CurrentPos */
    static CurrentPos: Vec2;
    //    /** IsMouseDown  */
    static IsMouseDown: boolean = false;

    static InitData() {
    }
    static UpdateScore() {
        if (SandBlast_GameData.Get_score() > SandBlast_GameStorage.data.mode_1.high_score) {
            SandBlast_GameStorage.data.mode_1.high_score = SandBlast_GameData.Get_score();

            SandBlast_GameStorage.saveData();
        }
    }
    static Get_score() {
        return SandBlast_GameStorage.data.mode_1.score;
    }
    static Set_score(value) {
        SandBlast_GameStorage.data.mode_1.score = value;
        SandBlast_GameStorage.saveData();
    }
    static Add_score(value) {
        SandBlast_GameData.Set_score(SandBlast_GameData.Get_score() + value);

        if (SandBlast_GameData.Get_high_score() < SandBlast_GameData.Get_score()) {
            SandBlast_GameData.Set_high_score(SandBlast_GameData.Get_score());
        }
    }

    static Get_high_score() {
        return SandBlast_GameStorage.data.mode_1.high_score;
    }
    static Set_high_score(value) {
        SandBlast_GameStorage.data.mode_1.high_score = value;
        SandBlast_GameStorage.saveData();
    }

    static ClearData() {

    }

    //    /** 新的一局 */
    static NewGame() {
        SandBlast_GameStorage.data.mode_1.isEnd = false;
        SandBlast_GameStorage.data.mode_1.score = 0;
        SandBlast_GameStorage.saveData();
    }

    //    /** 保存数据 */
    static SaveData() {
        let serialized = [];

        // for (let index = 0; index < SandBlast_GameData.arrCardGroups.length; index++) {
        //     const block: DragTetris_BlockGroup = SandBlast_GameData.arrCardGroups[index];
        //     let item = block.toJSON();
        //     serialized.push(item);
        // }

        // console.log(serialized);
        // SandBlast_GameStorage.data.map.arrCardGroups_temp = serialized;
        // SandBlast_GameStorage.saveData();
    }
    //    /** 保存数据 */
    static SaveGridData() {
        let serialized = [];

        // for (let x = 0; x < DragTetris_GameConfig.col; x++) {
        //     for (let y = 0; y < DragTetris_GameConfig.row; y++) {
        //         const scrGrid: DragTetris_Grid = DragTetris_CardFunctions.GetGrid(x, y);
        //         // console.log(`scrGrid`, scrGrid);

        //         if (scrGrid.block) {
        //             // console.log(`scrGrid.block`, scrGrid.block);
        //             let item = scrGrid.toJSON();
        //             serialized.push(item);
        //         }
        //     }
        // }

        // SandBlast_GameStorage.data.map.blocks = serialized;
        // SandBlast_GameStorage.saveData();
    }
}

window["SandBlast_GameData"] = SandBlast_GameData;